<template>
  <div class="container">
    <h2 class="handle-title">销售团队管理 > 销售团队</h2>
    <div class="handle-box">
      <div>
        <el-button class="add_btn" type="primary" @click="addRole">新增</el-button>
      </div>
    </div>
    <el-table
      :data="tableData"
      class="table"
      border>
      <el-table-column prop="deptname" label="机构名称"/>
      <el-table-column prop="usertruename" label="用户姓名"/>
      <el-table-column prop="deptdesc" label="简介"/>
      <el-table-column label="状态">
        <template #default="{row}">
          {{ row.deptstate == 1 ? "是" : "否" }}
        </template>
      </el-table-column>

      <el-table-column label="操作" width="200">
        <template #default="{row}">
          <el-button type="text" icon="el-icon-edit-outline" @click="goUpdate(row.roleid)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="totalNum">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {getDeptList} from "../../api/public/api";

export default {
  name: "Dept",
  data() {
    return {
      deptname: "",
      usertruename: '',
      deptdesc: '',
      deptstate:'',
      tableData: [],   //默认数据列表
      currentPage: 1, //默认第一页
      pageSize: 10,   //默认每页10条
      totalNum: 0,    //默认总条数
    }
  },
  mounted() {
    this.deptList()
  },
  methods: {
    //每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.deptList()
    },
    // 第几页
    handleCurrentChange(val) {
      this.currentPage = val;
      this.deptList()
    },
    //封装请求方法
    deptList() {
      let params = {
        pagenum: this.currentPage,
        pagesize: this.pageSize,
        usertruename: this.usertruename,
        deptname: this.deptname,
        deptstate: this.deptstate,
        deptdesc:this.deptdesc
      };
      getDeptList(params).then((res) => {
        this.tableData = res.data.pagedata.records;
        this.totalNum = res.data.pagedata.total;
      })
    },
    //Search搜索按钮
    goSearch() {
      this.deptList()
    },
    //新增角色
    addRole() {
      this.$router.push({
        path: "/demo",
        query: {}
      })
    },
    //修改
    goUpdate(id) {
      // console.log(id)
      this.$router.push({
        path: "/updaterole",
        query: {id}
      })
    },
    //权限管理
    goRight(id) {
      this.$router.push({
        path: "/right",
        query: {id}
      })
    },
    goOrder(id) {

    }
  },
}
</script>

<style>
.handle-title {
  line-height: 50px;
}
</style>

